package com.gxa.service.discrepancy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.DeviceLog;
import com.gxa.entity.discrepancy.VisitorList;
import com.gxa.entity.discrepancy.search.DeviceLogSearchMap;
import com.gxa.mapper.discrepancy.DeviceLogMapper;
import com.gxa.service.discrepancy.DeviceLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog> implements DeviceLogService {
    @Autowired
    private DeviceLogMapper mapper;


    @Override
    public PageInfo<DeviceLog> queryByPage(DeviceLogSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<DeviceLog> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getReason())) {
            wrapper.like("reason", map.getReason());
        }

        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("tigger_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<DeviceLog> pageInfo = new PageInfo<>(mapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }
}
